package com.example.goodsui.service;

import com.example.goodscommons.pojo.Book;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class GoodsUIServiceImpl implements GoodsUIService{

    @Resource
    private RestTemplate restTemplate;


    @Override
    public void testGoodsProvider() {
        String object=restTemplate.getForObject("http://goods-provider/provider/test",String.class);
        System.out.println(object);
    }

    @Override
    public List<Book> getBookList() {
        Book[] bookList=restTemplate.getForObject("http://goods-provider/provider/list",Book[].class);
        return Arrays.asList(bookList);
    }

    @Override
    public Book getBookDetail(Integer id) {
        Book book=restTemplate.getForObject("http://goods-provider/provider/detail/"+id,Book.class);
        return book;
    }

//
    @Override
    public String addBook(Book book) {
        String msg=restTemplate.postForObject("http://goods-provider/provider/add",book,String.class);
        return  msg;
    }

//    @Override
//    public Book getBookDetailById(Integer id) {
//        Book book = restTemplate.getForObject("http://goods-provider/provider/detail?id="+id, Book.class);
//        return book;
//    }
}
